<?php
  class Keke_witkey_zuopin_class{
        public $_db;
        public $_tablename;
	    public $_dbop;
   	 	      public $_zp_id;  
		 public $_zp_cat_id; 
		 public $_uid; 
		 public $_username; 
		 public $_zp_title;  
		 public $_zp_pic; 
		 public $_content; 
		 public $_ding;
		 public $_pub_time; 
		 public $_views;
         public $_is_show;
         public $_is_good;
         public $_good_time; 

	    public $_cache_config = array ('is_cache' => 0, 'time' => 0 );
	    public $_replace=0;  
	    public $_where;      
	     function  keke_witkey_zuopin_class(){ 
			 $this->_db = new db_factory ( );
			 $this->_dbop = $this->_db->create(DBTYPE);
			 $this->_tablename = TABLEPRE."witkey_zuopin";
		 }
	    
	    		public function getZp_id(){
			 return $this->_zp_id ;
		}
		public function getZp_cat_id(){
			 return $this->_zp_cat_id ;
		}
		public function getUid(){
			 return $this->_uid ;
		}
		public function getUsername(){
			 return $this->_username ;
		}
		public function getZp_title(){
			 return $this->_zp_title ;
		}
		public function getZp_source(){
			 return $this->_zp_source ;
		}
		public function getZp_pic(){
			 return $this->_zp_pic ;
		}
		public function getContent(){
			 return $this->_content ;
		}
		public function getDing(){
			 return $this->_ding ;
		}
		public function getPub_time(){
			 return $this->_pub_time ;
		}
		public function getViews(){
			 return $this->_views ;
		}
        public function getIs_show(){
            return $this->_is_show;
        }
        public function getIs_good(){
            return $this->_is_good;
        }
        public function getGood_time(){
            return $this->_good_time;
        }
		public function getWhere(){
			 return $this->_where ;
		}
		public function getCache_config() {
			return $this->_cache_config;
		}

	    		public function setZp_id($value){ 
			 $this->_zp_id = $value;
		}
		public function setZp_cat_id($value){ 
			 $this->_zp_cat_id = $value;
		}
		public function setUid($value){ 
			 $this->_uid = $value;
		}
		public function setUsername($value){ 
			 $this->_username = $value;
		}
		public function setZp_title($value){ 
			 $this->_zp_title = $value;
		}
		public function setZp_pic($value){ 
			 $this->_zp_pic = $value;
		}
		public function setContent($value){ 
			 $this->_content = $value;
		}
		public function setDing($value){ 
			 $this->_ding = $value;
		}
		public function setPub_time($value){ 
			 $this->_pub_time = $value;
		}
		public function setViews($value){ 
			 $this->_views = $value;
		}
        public function setIs_show($value){
            $this->_is_show =$value;
        }
        public function setIs_good($value){
            $this->_is_good = $value;
        }
        public function setGood_time($value){
            $this->_good_time = $value;
        }
		public function setWhere($value){ 
			 $this->_where = $value;
		}
		public function setCache_config($_cache_config) {
			 $this->_cache_config = $_cache_config; 
		}

	    
    	   public  function __set($property_name, $value) {

		 		$this->$property_name = $value; 

			}

			public function __get($property_name) { 

				if (isset ( $this->$property_name )) { 

					return $this->$property_name; 

				} else { 

					return null; 

				} 

			}

    	
	    /**
		 * insert into  keke_witkey_zuopin  ,or add new record
		 * @return int last_insert_id
		 */
		function create_keke_witkey_zuopin(){
		 		 $data =  array(); 

					if(!is_null($this->_zp_id)){ 
				 $data['zp_id']=$this->_zp_id;
			}
			if(!is_null($this->_zp_cat_id)){ 
				 $data['zp_cat_id']=$this->_zp_cat_id;
			}
			if(!is_null($this->_uid)){ 
				 $data['uid']=$this->_uid;
			}
			if(!is_null($this->_username)){ 
				 $data['username']=$this->_username;
			}
			if(!is_null($this->_zp_title)){ 
				 $data['zp_title']=$this->_zp_title;
			}
			if(!is_null($this->_zp_pic)){ 
				 $data['zp_pic']=$this->_zp_pic;
			}
			if(!is_null($this->_content)){ 
				 $data['content']=$this->_content;
			}
			if(!is_null($this->_ding)){ 
				 $data['ding']=$this->_ding;
			}
			if(!is_null($this->_pub_time)){ 
				 $data['pub_time']=$this->_pub_time;
			}
			if(!is_null($this->_views)){ 
				 $data['views']=$this->_views;
			}
            if(!is_null($this->_is_show)){
                $data['is_show']=$this->_is_show;
            }
            if(!is_null($this->_is_good)){
                $data['is_good']=$this->_is_good;
            }
            if(!is_null($this->_good_time)){
                $data['good_time'] = $this->_good_time;
            }

			 return $this->_zp_id = $this->_db->inserttable($this->_tablename,$data,1,$this->_replace); 
		 } 

	    /**
		 * edit table keke_witkey_zuopin
		 * @return int affected_rows
		 */
		function edit_keke_witkey_zuopin(){ 
		 		 $data =  array(); 
 
					if(!is_null($this->_zp_id)){ 
				 $data['zp_id']=$this->_zp_id;
			}
			if(!is_null($this->_zp_cat_id)){ 
				 $data['zp_cat_id']=$this->_zp_cat_id;
			}
			if(!is_null($this->_uid)){ 
				 $data['uid']=$this->_uid;
			}
			if(!is_null($this->_username)){ 
				 $data['username']=$this->_username;
			}
			if(!is_null($this->_zp_title)){ 
				 $data['zp_title']=$this->_zp_title;
			}
			if(!is_null($this->_zp_pic)){ 
				 $data['zp_pic']=$this->_zp_pic;
			}
			if(!is_null($this->_content)){ 
				 $data['content']=$this->_content;
			}
			if(!is_null($this->_ding)){ 
				 $data['ding']=$this->_ding;
			}
			if(!is_null($this->_pub_time)){ 
				 $data['pub_time']=$this->_pub_time;
			}
			if(!is_null($this->_views)){ 
				 $data['views']=$this->_views;
			}
            if(!is_null($this->_is_show)){
                $data['is_show']=$this->_is_show;
            }
            if(!is_null($this->_is_good)){
                $data['is_good']=$this->_is_good;
            }
            if(!is_null($this->_good_time)){
                $data['good_time'] = $this->_good_time;
            }

			if($this->_where){ 
				 return $this->_db->updatetable($this->_tablename,$data,$this->getWhere()); 
			 } 
			 else{ 
				 $where = array('zp_id' => $this->_zp_id); 
				 return $this->_db->updatetable($this->_tablename,$data,$where); 
			} 
		 } 

	    /**
		 * query table: keke_witkey_zuopin,if isset where return where record,else return all record
		 * @return array 
		 */
		function query_keke_witkey_zuopin($is_cache=0, $cache_time=0){ 
			 if($this->_where){ 
				 $sql = "select * from $this->_tablename where ".$this->_where; 
			 } 
			 else{ 
				 $sql = "select * from $this->_tablename"; 
			 } 
			//echo $sql;die();
			if ($is_cache) {
			 $this->_cache_config ['is_cache'] = $is_cache;
			}
			if ($cache_time) {
			 $this->_cache_config ['time'] = $cache_time;
			 }
			 if ($this->_cache_config ['is_cache']) {
			     if (CACHE_TYPE) {
					 $keke_cache = new keke_cache_class ( CACHE_TYPE );
					 $id = $this->_tablename . ($this->_where?"_" .substr(md5 ( $this->_where ),0,6):'');
						$data = $keke_cache->get ( $id );
							if ($data) {
								return $data; 
							} else { 
								$res = $this->_dbop->query ( $sql ); 
								$keke_cache->set ( $id, $res,$this->_cache_config['time'] ); 
					 			$this->_where = ""; 
								return $res;
 							} 
						} 
			 }else{
			 	$this->_where = ""; 
				return  $this->_dbop->query ( $sql );
 			 }
		 } 

	    /**
		 * query count keke_witkey_zuopin records,if iset where query by where 
		 * @return int count records
		 */
		function count_keke_witkey_zuopin(){ 
			 if($this->_where){ 
				 $sql = "select count(*) as count from $this->_tablename where ".$this->_where; 
			 } 
			 else{ 
				 $sql = "select count(*) as count from $this->_tablename"; 
			 } 
			 $this->_where = ""; 
			 return $this->_dbop->getCount($sql); 
		 } 

	    /**
		 * delete table keke_witkey_zuopin, if isset where delete by where 
		 * @return int deleted affected_rows 
		 */
		function del_keke_witkey_zuopin(){ 
			 if($this->_where){ 
				 $sql = "delete from $this->_tablename where ".$this->_where; 
			 } 
			 else{ 
				 $sql = "delete from $this->_tablename where zp_id = $this->_zp_id "; 
			 } 
			 $this->_where = ""; 
			 return $this->_dbop->execute($sql); 
		 } 

	   
	    
	    
   }
 ?>